/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.leospa.main;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.SwingConstants;
import javax.swing.Timer;

import com.leospa.bean.Command_0;
import com.leospa.bean.Command_1;
import com.leospa.clients.SerialClient;
import com.leospa.properties.ColorPropertiesFile;
import com.leospa.properties.ConfigPropertiesFile;
import com.leospa.properties.ContentPropertiesFile;

/**
 *
 * @author ADMIN
 */
public class ConfirmationAfterTimeSelection {

	/**
	 * Creates new form ConfirmationScreen
	 */
	int count = 0;
	int time;
	int price;
	int step_count;
	Timer timer;
	MainScreen mainScreen;
	javax.swing.GroupLayout layout;
	public ConfirmationAfterTimeSelection(int time, int price, int  step_count,MainScreen mainScreen, javax.swing.GroupLayout layout) {
		this.layout = layout;
		this.mainScreen = mainScreen;
		this.time = time;
		this.price = price;
		this. step_count = step_count;
		
//		try {
//			URL imgURL = new File( "./images/backgrond.png" ).toURI().toURL();
//			setContentPane(new JLabel(new ImageIcon(imgURL)));
//		} catch (MalformedURLException e) {
//			// TODO Auto-generated catch block
//			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){
//		}
		
		initComponents();
		startTime();
		int min = time/60;
		int sec = time%60;
		String minSt =""+min;
		 if(min <10){
			 minSt="0"+min;
		}
		String secSt = ""+sec;
		if(sec <10){
			 secSt ="0"+sec;
		}
		jLabel6.setText(""+minSt+":"+secSt+" Min");
		if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("Total Time Minuts: "+minSt+" and in Seconds: "+secSt);}

		// SerialClient.getCardSerialNumber();
	}
	
	public void startTime(){
		timer = new Timer(1000, new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// Code to be executed
				count++;
				if(count%ConfigPropertiesFile.CARD_READ_DELAY == 0){
					if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Call Card Read==== After 5 second");}
					String carderialNumber = SerialClient.getCardSerialNumber();
					if(carderialNumber!= null && carderialNumber.equals(Util.getUtilInstance().getRf_id_card_number())){
						Util.getUtilInstance().setRf_id_card_number(carderialNumber);
						if(carderialNumber != null){
							timer.stop();	
							jPanel1.setVisible(false);
							LoadingScreen2 loadingScreen2 = new LoadingScreen2(ConfirmationAfterTimeSelection.this.time,ConfirmationAfterTimeSelection.this.price,mainScreen,layout);
							loadingScreen2.setLayout();
							
						}
					}									
					if (ConfigPropertiesFile.DEMO_MODE == true) {
						timer.stop();		
						Util.getUtilInstance().setRf_id_card_number("C569647F");
						jPanel1.setVisible(false);
						if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("Demo Mode==============================,");}
						LoadingScreen2 loadingScreen2 = new LoadingScreen2(ConfirmationAfterTimeSelection.this.time,ConfirmationAfterTimeSelection.this.price,mainScreen,layout);
						loadingScreen2.setLayout();
						
					}	
				}
				if (count == 30) {
					timer.stop();
				     MainScreen leoSpaMainFrame = new MainScreen();
				     leoSpaMainFrame.setVisible(true);
				     mainScreen.dispose();
				}
				
			}
		});
		timer.setRepeats(true); // Only execute once
		timer.start(); // Go go go!
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		 jDialog1 = new javax.swing.JDialog();
	        jPanel1 = new javax.swing.JPanel();
	        jPanel2 = new javax.swing.JPanel();
	        jLabel1 = new javax.swing.JLabel();
	        jLabel2 = new javax.swing.JLabel();
	        jButton1 = new javax.swing.JButton();
	        jLabel5 = new javax.swing.JLabel();
	        jLabel6 = new javax.swing.JLabel();

	        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
	        jDialog1.getContentPane().setLayout(jDialog1Layout);
	        jDialog1Layout.setHorizontalGroup(
	            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 400, Short.MAX_VALUE)
	        );
	        jDialog1Layout.setVerticalGroup(
	            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 300, Short.MAX_VALUE)
	        );

	        jPanel1.setMaximumSize(new java.awt.Dimension(800, 1280));
	        jPanel1.setMinimumSize(new java.awt.Dimension(800, 1280));
	        jPanel1.setOpaque(false);
	        jPanel1.setPreferredSize(new java.awt.Dimension(800, 1280));
	        Color color = Color.decode(ColorPropertiesFile.Popup_BG_Color);
	        jPanel2.setBackground(color);
	        jPanel2.setPreferredSize(new java.awt.Dimension(786, 768));

	        color = Color.decode(ColorPropertiesFile.Popup_Header_BG_Color);
	        jLabel1.setBackground(color);
	        jLabel1.setFont(new java.awt.Font("SansSerif", 1, 48)); // NOI18N
	        color = Color.decode(ColorPropertiesFile.Popup_Text_Color);

	        jLabel1.setForeground(color);
	        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        
	        Command_1 command_1 = Util.getUtilInstance().getCommand_1();
        	Command_0 command_0 = Util.getUtilInstance().getCommand_0();
        	jLabel1.setOpaque(true);

	        jLabel2.setFont(new java.awt.Font("SansSerif", 0, 45)); // NOI18N
	        jLabel2.setForeground(color);
	        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	        //changes for allexclusive plan user and user with credit 0 confirmation message
	        /*if(GuthabenInfomMoneyScreen.currCredit<=0 && GuthabenInfomMoneyScreen.SHOWPRICE!=0) {
	        	jLabel2.setText(ContentPropertiesFile.ShoppingContent);}
	        else {
	        	jLabel2.setText(ContentPropertiesFile.Confirmation_Meaasge);}*/
	        if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Current Select Amount: "+price+", And Credit: "+command_1.getCREDIT()+", shoppingcart:"+command_0.getSHOPPINGCART());}
	        if(command_0.getSHOPPINGCART().equals("1") && Integer.parseInt(command_1.getCREDIT()) < price) {
        		jLabel1.setText(ContentPropertiesFile.Confirmation_Cart);
        		jLabel2.setText(ContentPropertiesFile.ShoppingContent);
        	}
        	else {
        		jLabel1.setText(ContentPropertiesFile.Confirmation);
        		jLabel2.setText(ContentPropertiesFile.Confirmation_Meaasge);
        	}
	        
	        try {
				URL imgURL = new File( "./images/3.png" ).toURI().toURL();
				jButton1.setIcon(new javax.swing.ImageIcon(imgURL)); // NOI18N
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){e.printStackTrace();}
			}
	        jButton1.setOpaque(false);
	        jButton1.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	                jButton1ActionPerformed(evt);
	            }
	        });

	        jLabel5.setFont(new java.awt.Font("SansSerif", 1, 45)); // NOI18N
	        jLabel5.setForeground(color);
	        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
	        jLabel5.setText(ContentPropertiesFile.Time);

	        jLabel6.setFont(new java.awt.Font("SansSerif", 1, 45)); // NOI18N
	        jLabel6.setForeground(color);
	        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	        jLabel6.setText("30:00 Min");

	
	        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
	        jPanel2.setLayout(jPanel2Layout);
	        jPanel2Layout.setHorizontalGroup(
	            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel2Layout.createSequentialGroup()
	                .addContainerGap()
	                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(jPanel2Layout.createSequentialGroup()
	                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE)
	                        .addGap(46, 46, 46)
	                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
	                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
	                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                        .addContainerGap())))
	            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
	                .addContainerGap(68, Short.MAX_VALUE)
	                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
	                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 637, javax.swing.GroupLayout.PREFERRED_SIZE))
	                .addGap(81, 81, 81))
	        );
	        jPanel2Layout.setVerticalGroup(
	            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel2Layout.createSequentialGroup()
	                .addGap(96, 96, 96)
	                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
	                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
	                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
	        );

	        //================

	        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
	        jPanel1.setLayout(jPanel1Layout);
	        jPanel1Layout.setHorizontalGroup(
	            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel1Layout.createSequentialGroup()
	                .addGap(0, 0, 0)
	                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(150, Short.MAX_VALUE))
	        );
	        jPanel1Layout.setVerticalGroup(
	            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(jPanel1Layout.createSequentialGroup()
	                .addGap(0, 0, 0)
	                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(730, Short.MAX_VALUE))
	        );
	
	}// </editor-fold>
	
	public void setLayout(){
        layout = new javax.swing.GroupLayout(mainScreen.getContentPane());
        mainScreen.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(75, 75, 75))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(94, 94, 94))
        );
        mainScreen.pack();
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		timer.stop();
		jPanel1.setVisible(false);
		
		Command_1 command_1=Util.getUtilInstance().getCommand_1();
		 if(command_1.getSHOWPRICE().equals("0")){
			 TimerWithoutAmmount timerWithoutAmmount=new TimerWithoutAmmount(mainScreen, layout);
			 timerWithoutAmmount.setLayout();
		 }
		 else
		 {
			   TimerWithAmount timerWithAmount = new TimerWithAmount(mainScreen,layout);
				timerWithAmount.setLayout();
		 }
		/*GuthabenInfoScreen infoScreen=new GuthabenInfoScreen(mainScreen, layout);
		infoScreen.setLayout();*/
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed" desc=" Look and feel setting
		// code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.
		 * html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(ConfirmationAfterTimeSelection.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(ConfirmationAfterTimeSelection.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(ConfirmationAfterTimeSelection.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(ConfirmationAfterTimeSelection.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>
		// </editor-fold>
		// </editor-fold>
		// </editor-fold>
//		new ConfirmationAfterTimeSelection(10,0,0).setVisible(true);
		/* Create and display the form */
//		java.awt.EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				
//			}
//		});
	}

	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JDialog jDialog1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	// End of variables declaration
}
